package leetcode;

public class twenty2 {
    public static int mySqrt(int x) {
        long left=0;
        long right=x;
        if(x==0){
            return 0;
        }
        while(left<right){
            long mid=left+(right-left+1)/2;
            if(mid*mid<=x){
                left=mid;
            }else{
                right=mid-1;
            }
        }
        return (int)left;

    }

    public static void main(String[] args) {
        int i = mySqrt(2147483647);
        System.out.println(i);

    }
}
